/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.resourceManager;

import java.util.ArrayList;
import java.util.List;

import org.nudt.jCloud.infrastructure.Cluster;
import org.nudt.jCloud.infrastructure.Host;
import org.nudt.jCloud.simulation.SimEvent;

public class StaticParRM extends ResManager{
	private List<ResManager> rMs;
	private int partitions;
	private List<Host> unManagedHosts;
	
	public StaticParRM(String name, Cluster cluster) {
		super(name, cluster);
		rMs = new ArrayList<ResManager>();
		partitions = 0;
		setUnManagedHosts(new ArrayList<Host>());
		for(int i=0; i<getHostList().size(); ++i){
			unManagedHosts.add(getHostList().get(i));
		}
	}
	
	public void addRM(ResManager rM){
		rMs.add(rM);
		partitions++;
	}
	
	public void addRM(double percent){
		ResManager rM = new GeneralShareStateRM("MonolithicRM"+partitions, null);
		int hostCount = (int) Math.floor(getHostList().size()*percent);
		if(hostCount>unManagedHosts.size()){
			throw new RuntimeException("Cannot init the resource manager that request "+percent+"resource.");
		}else{
			for(int i=0; i<hostCount; ++i){
				rM.addHost(unManagedHosts.get(0));
				unManagedHosts.remove(0);
			}
		}
		addRM(rM);
	}
	
	public List<ResManager> getRMs() {
		return rMs;
	}

	public void setRMs(List<ResManager> rMs) {
		this.rMs = rMs;
	}

	public int getPartitions() {
		return partitions;
	}

	public void setPartitions(int partitions) {
		this.partitions = partitions;
	}

	public List<Host> getUnManagedHosts() {
		return unManagedHosts;
	}

	public void setUnManagedHosts(List<Host> unManagedHosts) {
		this.unManagedHosts = unManagedHosts;
	}

	@Override
	public void processEvent(SimEvent event) {
		// TODO Auto-generated method stub
		
	}

}
